﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Invini.Tools
{
    public class PercentConverter : IValueConverter
    {
        public int Precision
        {
            get;
            set;
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double dblValue = System.Convert.ToDouble(value);
            return dblValue.ToString(String.Concat("P", this.Precision), culture);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string text = (string)value;
            return double.Parse(text.Substring(0, text.Length - 1)) / 100.0;
        }
    }
}
